package org.idea.spring.bean.listener;

import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.stereotype.Component;

/**
 * @author linhao
 * @date created in 6:25 下午 2020/10/11
 */
@Component
public class MyApplicationListener implements ApplicationListener {
    @Override
    public void onApplicationEvent(ApplicationEvent event) {
        System.out.println("接收了一个事件====" + event);
    }

    public static void main(String[] args) {
        AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
        ctx.scan("org.idea.spring.bean.listener");
        ctx.refresh();
        ctx.close();
//        ctx.publishEvent(new ApplicationEvent("我手动发布了一个事件") {
//            @Override
//            public Object getSource() {
//                return super.getSource();
//            }
//        });
//        ctx.close();
    }
}
